<template>
  <view class="uni-tab-bar">
    <view v-for="(tab, index) in list" :key="index" class="uni-tab-bar-item" @click="handleClick(index)">
      <image :src="current === index ? tab.selectedIconPath : tab.iconPath"></image>
      <text :class="{ 'uni-tab-bar-text': true, 'uni-tab-bar-text-active': current === index }">{{ tab.text }}</text>
    </view>
  </view>
</template>

<style scoped>
  .uni-tab-bar {
    display: flex;
    justify-content: space-between;
    padding: 10rpx;
    height: 100rpx;
    background-color: #fff;
    box-shadow: 0 -1rpx 10rpx rgba(0, 0, 0, 0.1);
  }

  .uni-tab-bar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 33.33%;
  }

  .uni-tab-bar-text {
    font-size: 22rpx;
    color: #666;
  }

  .uni-tab-bar-text-active {
    color: #007aff;
  }
</style>

<script>
  export default {
    name: 'uni-tab-bar',
    props: {
      list: {
        type: Array,
        required: true
      },
      current: {
        type: Number,
        default: 0
      }
    },
    methods: {
      handleClick(index) {
        if (index !== this.current) {
          this.$emit('change', { index });
        }
      }
    }
  }
</script>
